package com.its.us;

import com.its.us.sk.server.tcp.NettyTcpServer;
import com.its.us.sk.server.ws.NettyWsServer;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @Author: master
 * @Date: 2020/10/28 8:21
 * @Version: 1.0
 */
// 排除数据源
//@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@ComponentScan(basePackages = {"com.its.us"})
@PropertySource(value = {"classpath:config/config.properties"},
        encoding = "utf-8",
        ignoreResourceNotFound = true)
@EnableTransactionManagement
@MapperScan("com.its.us.web.mapper")
@EnableAutoConfiguration
// 异步发送消息
@EnableBinding({Source.class})
@EnableAsync
//@CrossOrigin(origins = "*",maxAge = 3600)
public class ApplicationRun {
    public static void main(String[] args) {
        SpringApplication.run(ApplicationRun.class, args);
        //runNettyServer();
    }

    /**
     * netty服务
     */
    private static void runNettyServer(){
        try {
            // 开启tcp服务
            Thread t1 = new Thread(() -> {
                try {
                    new NettyTcpServer(5004).start();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
            t1.start();

            // 开启ws服务
            Thread t2 = new Thread(() -> {
                try {
                    new NettyWsServer(5005).start();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
            t2.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
